// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef HOME_H_
#define HOME_H_

#include <Wt/WApplication>
#include <Wt/WContainerWidget>

namespace Wt {
  class WMenu;
  class WStackedWidget;
  class WTabWidget;
  class WTreeNode;
  class WTable;
  class WComboBox;
}

class Download;

using namespace Wt;

/*
 * A utility container widget which defers creation of its single
 * child widget until the container is loaded (which is done on-demand
 * by a WMenu). The constructor takes the create function for the
 * widget as a parameter.
 *
 * We use this to defer widget creation until needed.
 */
template <typename Function>
class DeferredWidget : public WContainerWidget
{
public:
  DeferredWidget(Function f)
	: f_(f) { }

private:
  void load() {
	WContainerWidget::load();
	if (count() == 0)
	  addWidget(f_());
  }

  Function f_;
};

template <typename Function>
DeferredWidget<Function> *deferCreate(Function f)
{
  return new DeferredWidget<Function>(f);
}

class Home : public WApplication
{
public:
  Home(const WEnvironment& env,
	   const std::string& title,
	   const std::string& resourceBundle, const std::string& cssPath);

  virtual ~Home();

  void googleAnalyticsLogger();


protected:
  void init();

  WString tr(const char *key);

private:
  WWidget *homePage_;

  WStackedWidget *contents_;

  WWidget *initHome();

  WWidget *introduction();
  WWidget *features();
  WWidget *documentation();
  WWidget *download();
  WWidget *faq();

  Download*		m_download;

  WMenu *mainMenu_;

  int language_;

  void readNews(WTable *newsTable, const std::string& newsfile);

  WWidget *wrapView(WWidget *(Home::*createFunction)());

  void updateTitle();
  void setup();
  void logInternalPath(const std::string& path);

  WContainerWidget *sideBarContent_;
};

WApplication *createHomeApplication(const WEnvironment& env);

#endif // HOME_H_
